package com.bing.habit.service.impl;

import com.bing.habit.mapper.TomatoRecordDAO;
import com.bing.habit.entity.TomatoRecord;
import com.bing.habit.service.TomatoRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TomatoRecordServiceImpl implements TomatoRecordService {

    @Autowired
    TomatoRecordDAO tomatoRecordDAO;

    @Override
    public void add(TomatoRecord tomatoRecord) {
        tomatoRecordDAO.insert(tomatoRecord);
    }

    @Override
    public List<TomatoRecord> list(int uid) {
        return tomatoRecordDAO.findAllByUid(uid);
    }

    @Override
    public List<TomatoRecord> listToday(int uid) {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return tomatoRecordDAO.listDay(uid, today);
    }

    @Override
    public List<TomatoRecord> listWeek(int uid) {
        return tomatoRecordDAO.listWeek(uid);
    }
}
